import { createRouter, createWebHistory } from 'vue-router'
import { checkLogin } from '../api/index'

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/login'),
    meta: {
      needLogin: false
    }
  },
  {
    path: '/layout',
    component: () => import('../layout/index'),
    children: [
      {
        path: '/user',
        name: 'User',
        component: () => import('../views/user'),
        meta: {
          needLogin: false
        }
      },
      {
        path: '/weiboAnalysis',
        name: 'weiboAnalysis',
        component: () => import('../views/weiboAnalysis'),
        meta: {
          needLogin: false
        }
      },
      {
        path: '/weiboCovid',
        name: 'weiboCovid',
        component: () => import('../views/weiboCovid'),
        meta: {
          needLogin: false
        }
      },
      {
        path: '/weibo/analysis',
        name: 'wbAnalysis',
        component: () => import('../views/weiboAnalysis/analysis.vue'),
        meta: {
          needLogin: false
        }
      },
      {
        path: '/weiboSpider',
        name: 'analysis',
        component: () => import('../views/weiboSpider'),
        meta: {
          needLogin: false
        }
      },
    ]
  },

]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to, from, next) => {
  if (to.meta.needLogin) {
    next()
    // next({
    //   path: '/login'
    // })
  } else {
    next()
  }
})
export default router
